﻿using System.Collections;
using System.Collections.Generic;

using UnityEngine;

public class ResLayerName
{
    public const int MAX_LAYER_COUNT = 30;
    public static Dictionary<int, string> layerNameMap { get; private set; }
    public static string[] layerNames { get; private set; }

    static ResLayerName()
    {
        layerNameMap = new Dictionary<int, string>();
        layerNames = new string[MAX_LAYER_COUNT];
        layerNames[0] = layerNameMap[0] = "Layer0";
        for (int i = 0; i < MAX_LAYER_COUNT - 1; i++)
        {
            layerNames[i + 1] = layerNameMap[1 << i] = "Layer" + (i + 1);
        }
    }

    public static void ChangeLayerName(int layerId, string name)
    {
        if (layerNames.Length > layerId)
        {
            if (layerId > 0)
            {
                layerNames[layerId] = name;
                layerNameMap[1 << (layerId - 1)] = name;
            }
            else if (layerId == 0)
            {
                layerNames[0] = name;
                layerNameMap[0] = name;
            }
        }
    }

    public static int IDToMask(int id)
    {
        if (id <= 0)
            return 0;
        else
            return 1 << (id - 1);
    }

    public static bool MaskContains(int mask, int id)
    {
        if (id == 0 || mask == -1)
            return true;
        else
            return (mask & (1 << (id - 1))) != 0;
    }
}
